package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type ResponseData struct {
	Code int `json:"code"`
	Msg  string `json:"msg"`
	Data interface{} `json:"data,omitempty"`
	Rows interface{} `json:"rows,omitempty"`
	Total interface{} `json:"total,omitempty"`
}

func RespFail(c *gin.Context,msg string){
	Resp(c,-1,nil,msg)
}

func RespOk(c *gin.Context,data interface{}){
	msg := "Success"
	Resp(c,0,data,msg)
}

func RespOkList(c *gin.Context,lists interface{},total interface{}){
	//分页数目,
	RespList(c,0,lists,total)
}

func Resp(c *gin.Context,code int,data interface{},msg string)  {
	c.JSON(http.StatusOK, &ResponseData{
		Code: code,
		Msg:  msg,
		Data: data,
	})
}

func RespList(c *gin.Context,code int,data interface{},total interface{})  {
	c.JSON(http.StatusOK, &ResponseData{
		Code: code,
		Rows:  data,
		Total: total,
	})
}
